from rest_framework.response import Response
from .constant import CODE_SUCCESS, MSG_SUCCESS
from rest_framework import status


class JsonResponse(Response):
    def __init__(self, data=None, code=CODE_SUCCESS, message=MSG_SUCCESS, status=None, template_name=None, headers=None, exception=False, content_type=None):
        super().__init__(data=None, status=status, template_name=template_name,
                         headers=headers, exception=exception, content_type=content_type)
        self._code = code
        self._message = message
        self._data = data
        self.data = {"code": code, "message": message, "data": data}

    @property
    def code(self):
        return self._code

    @code.setter
    def code(self, value):
        self._code = value

    @property
    def message(self):
        return self._message

    @message.setter
    def message(self, value):
        self._message = value

    @property
    def data(self):
        return self._data

    @data.setter
    def data(self, value):
        self._data = value
